package patrol.mobile.com.mobilepatrol.activity.security.emergency;

import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.activity.security.ConsTitles;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.CheckEntityBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;
import patrol.mobile.com.mobilepatrol.widget.MyRadioGroup;

/**
 * Created by fuzhen.li on 2018/9/18.
 */
public class EmergencyCheck2Activity extends BaseActivity {


    @BindView(R.id.tv_orgName)
    EditText tvOrgName;
    @BindView(R.id.tv_title)
    EditText tvTitle;
    @BindView(R.id.tv_checkorgId)
    EditText tvCheckorgId;
    @BindView(R.id.rb_safe)
    RadioButton rbSafe;
    @BindView(R.id.rb_ergent)
    RadioButton rbErgent;
    @BindView(R.id.rb_total)
    RadioButton rbTotal;
    @BindView(R.id.rg_check_type)
    MyRadioGroup rgCheckType;
    @BindView(R.id.tv_checkCategory)
    TextView tvCheckCategory;
    @BindView(R.id.rb_mid)
    RadioButton rbMid;
    @BindView(R.id.rb_end)
    RadioButton rbEnd;
    @BindView(R.id.rb_often)
    RadioButton rbOften;
    @BindView(R.id.rg_check_way)
    RadioGroup rgCheckWay;
    @BindView(R.id.tv_checkType)
    TextView tvCheckType;
    @BindView(R.id.tv_checkLeader)
    EditText tvCheckLeader;
    @BindView(R.id.tv_checkPerson)
    EditText tvCheckPerson;
    @BindView(R.id.tv_checkDate)
    TextView tvCheckDate;
    @BindView(R.id.tv_next)
    TextView tvNext;
    private CheckEntityBean checkEntityBean = null;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_emergency_check_add;
    }

    @Override
    public void setListener() {


    }

    @Override
    public void initData() {
        super.initData();
        Intent intent = getIntent();
        if (intent != null) {
            requestData(intent.getStringExtra("id"));
        }
    }

    @Override
    public void initTitle() {
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(EmergencyCheck2Activity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        tv_center_title.setText(ConsTitles.EMERGENCY_CHECK_2);
        tvCheckLeader.setEnabled(false);
        tvCheckorgId.setEnabled(false);
        tvCheckPerson.setEnabled(false);
        tvOrgName.setEnabled(false);
        tvTitle.setEnabled(false);
    }


    @OnClick({R.id.tv_next})
    public void onTVClick(View v) {

        switch (v.getId()) {

            case R.id.tv_next:
                // startActivity(EmergencyCheck4Activity.class);
                Intent intent = new Intent(this, EmergencyCheckInfoActivity.class);
                intent.putExtra("details", (ArrayList) checkEntityBean.getCheckDetailList());
                startActivity(intent);
                break;

        }

    }

    private void requestData(String id) {
        HttpSender sender = new HttpSender(this, baseUrl, Urls.IEMERGENCY_CHECK__ENTITY_LIST);
        HashMap<String, String> map = new HashMap<>();
        map.put("id", id);
        sender.requestPost(map, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                checkEntityBean = GsonUtil.GsonToBean(response, CheckEntityBean.class);
                tvOrgName.setText(checkEntityBean.getOrg().getOrgName());
                tvTitle.setText(checkEntityBean.getTitle());
                tvCheckorgId.setText(checkEntityBean.getCheckorgId().getOrgName());
                tvCheckCategory.setText(checkEntityBean.getCheckCategory());
                tvCheckType.setText(checkEntityBean.getCheckType());
                tvCheckLeader.setText(checkEntityBean.getCheckLeader());
                tvCheckPerson.setText(checkEntityBean.getCheckPerson());
                tvCheckDate.setText(checkEntityBean.getCheckDate());
                switch (checkEntityBean.getCheckType()) {
                    case "年中":
                        rbMid.setChecked(true);
                        break;
                    case "年末":
                        rbEnd.setChecked(true);
                        break;
                    case "经常":
                        rbOften.setChecked(true);
                        break;

                }
                switch (checkEntityBean.getCheckCategory()) {
                    case "安全生产":
                        rbSafe.setChecked(true);
                        rbErgent.setChecked(false);
                        rbTotal.setChecked(false);
                        break;
                    case "应急检查":
                        rbErgent.setChecked(true);
                        rbSafe.setChecked(false);
                        rbTotal.setChecked(false);
                        break;
                    case "综治维稳":
                        rbTotal.setChecked(true);
                        rbErgent.setChecked(false);
                        rbSafe.setChecked(false);
                        break;

                }
            }
        });
    }

}
